	var widgetEditTable = function (){};
	
	widgetEditTable.prototype.populate = function(objectTableDetail)
	{
		if(!objectTableDetail)
			return;
		
		if('id' in objectTableDetail)
			dom('input-table-id').value = objectTableDetail.id;
		if('number' in objectTableDetail)
			dom('input-table-number').value = objectTableDetail.number;
		if('maxPersons' in objectTableDetail)
			dom('input-table-maxPerson').value = objectTableDetail.maxPersons;
		if('status' in objectTableDetail)
			dom('input-table-status').value = objectTableDetail.status;
		if('type' in objectTableDetail)
			dom('input-table-type').value = objectTableDetail.type;	
	};
	
	widgetEditTable.prototype.retrieve = function(){
		return {
			id : dom('input-table-id').value,
			number : dom('input-table-number').value,
			maxPersons : dom('input-table-maxPerson').value,
			status : dom('input-table-status').value,
			type : dom('input-table-type').value
		};
	};
	
	$(function(){
		window.widget_selected_tables = new widgetSelectItems('div-selected-tables', tableList);
		
		window.widget_edit_table = new widgetEditTable();
		
		$(".div-table").click(selectTableToEdit);
		
		$("#button-new").click(function(){
			widget_edit_table.populate({
				id : '',
				number : '',
				maxPersons : '',
				status : '',
				type : ''
			});
		});
		
		$("#button-save").click(function(){
			var jsonForPost = widget_edit_table.retrieve();
			var strUrl  = 'saveTableSetting.action';
			jQuery.ajax ({
				url: strUrl,
				contentType:"application/json",
				type: "POST",
				cache: false,
				processData: false,
				dataType: "json",
				data: JSON.stringify(jsonForPost),
			    success: function(jsonRes)
			    {
					alert(jsonRes.status);
					window.location.reload();
			    }
		    });
		});
	});
	
	function selectTableToEdit(e){
		var tableId = e.srcElement.tableId;
		var table = widget_selected_tables.getItem(tableId);
		
		widget_edit_table.populate({
			id : tableId,
			number : table.number,
			maxPersons : table.maxPersons,
			status : table.status,
			type : table.type
		});
	}
	
